//
//  GoEasyJsonUtils.swift
//  GoEasy
//
//  Created by 冯传宝 on 1/6/16.
//  Copyright © 2016 uwantsoft. All rights reserved.
//

import Foundation
class GoEasyJsonUtils {
    
    class func dictAsJsonString(dict: [String:AnyObject]) -> String{
        do{
            let jsonData = try NSJSONSerialization.dataWithJSONObject(dict, options: NSJSONWritingOptions.PrettyPrinted)
            let str = NSString(data: jsonData, encoding: NSUTF8StringEncoding)?.stringByReplacingOccurrencesOfString(" ", withString: "")
            return str!
        }catch{
            print("ERROR when parse JSON")
        }
        return ""
    }
    
    class func dataAsDict(data: NSData) -> NSMutableDictionary{
        do{
            let json = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as! NSMutableDictionary
            return json
        }catch{
            print("Error when parse json string to json object")
        }
        return NSMutableDictionary()
    }
}